def is_prime(n):
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return True






primes = []
a = input()
numbers = []
new = []
e = a[0]
numbers.append(e)
for i in range(3):
    if len(a) < 4:
        break
    else:
        b = a[i] + a[i + 1]
        numbers.append(b)

for i in range(2):
    if len(a) < 4:
        break
    else:
        b = a[i] + a[i + 1] + a[i + 2]
        numbers.append(b)

numbers.append(a)



for i in range(7):
    if len(a) < 4:
        break
    else:
        if is_prime(int(numbers[i])) == True:
            prime = int(numbers[i])
            primes.append(prime)


max = 0

for i in range(len(primes)):
    if primes[i] > max:
        max = primes[i]

print(max)

